home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / elispman.lha / elispman / elisp-11 (.txt) < prev    next >
GNU Info File  |  1993-06-01  |  49KB  |  928 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  4. Emacs Version 19.
  5.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  6. Cambridge, MA 02139 USA
  7.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided that
  13. the entire resulting derived work is distributed under the terms of a
  14. permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that this permission notice may be stated in a
  18. translation approved by the Foundation.
  19. File: elisp,  Node: Syntax Errors,  Next: Compilation Errors,  Prev: Debugger,  Up: Debugging
  20. Debugging Invalid Lisp Syntax
  21. =============================
  22.    The Lisp reader reports invalid syntax, but cannot say where the real
  23. problem is.  For example, the error "End of file during parsing" in
  24. evaluating an expression indicates an excess of open parentheses (or
  25. square brackets).  The reader detects this imbalance at the end of the
  26. file, but it cannot figure out where the close parenthesis should have
  27. been.  Likewise, "Invalid read syntax: ")"" indicates an excess close
  28. parenthesis or missing open parenthesis, but not where the missing
  29. parenthesis belongs.  How, then, to find what to change?
  30.    If the problem is not simply an imbalance of parentheses, a useful
  31. technique is to try `C-M-e' at the beginning of each defun, and see if
  32. it goes to the place where that defun appears to end.  If it does not,
  33. there is a problem in that defun.
  34.    However, unmatched parentheses are the most common syntax errors in
  35. Lisp, and we can give further advice for those cases.
  36. * Menu:
  37. * Excess Open::     How to find a spurious open paren or missing close.
  38. * Excess Close::    How to find a spurious close paren or missing open.
  39. File: elisp,  Node: Excess Open,  Next: Excess Close,  Up: Syntax Errors
  40. Excess Open Parentheses
  41. -----------------------
  42.    The first step is to find the defun that is unbalanced.  If there is
  43. an excess open parenthesis, the way to do this is to insert a close
  44. parenthesis at the end of the file and type `C-M-b' (`backward-sexp').
  45. This will move you to the beginning of the defun that is unbalanced.
  46. (Then type `C-SPC C-_ C-u C-SPC' to set the mark there, undo the
  47. insertion of the close parenthesis, and finally return to the mark.)
  48.    The next step is to determine precisely what is wrong.  There is no
  49. way to be sure of this except to study the program, but often the
  50. existing indentation is a clue to where the parentheses should have
  51. been.  The easiest way to use this clue is to reindent with `C-M-q' and
  52. see what moves.
  53.    Before you do this, make sure the defun has enough close parentheses.
  54. Otherwise, `C-M-q' will get an error, or will reindent all the rest of
  55. the file until the end.  So move to the end of the defun and insert a
  56. close parenthesis there.  Don't use `C-M-e' to move there, since that
  57. too will fail to work until the defun is balanced.
  58.    Then go to the beginning of the defun and type `C-M-q'.  Usually all
  59. the lines from a certain point to the end of the function will shift to
  60. the right.  There is probably a missing close parenthesis, or a
  61. superfluous open parenthesis, near that point.  (However, don't assume
  62. this is true; study the code to make sure.)  Once you have found the
  63. discrepancy, undo the `C-M-q', since the old indentation is probably
  64. appropriate to the intended parentheses.
  65.    After you think you have fixed the problem, use `C-M-q' again.  It
  66. should not change anything, if the problem is really fixed.
  67. File: elisp,  Node: Excess Close,  Prev: Excess Open,  Up: Syntax Errors
  68. Excess Close Parentheses
  69. ------------------------
  70.    To deal with an excess close parenthesis, first insert an open
  71. parenthesis at the beginning of the file and type `C-M-f' to find the
  72. end of the unbalanced defun.  (Then type `C-SPC C-_ C-u C-SPC' to set
  73. the mark there, undo the insertion of the open parenthesis, and finally
  74. return to the mark.)
  75.    Then find the actual matching close parenthesis by typing `C-M-f' at
  76. the beginning of the defun.  This will leave you somewhere short of the
  77. place where the defun ought to end.  It is possible that you will find
  78. a spurious close parenthesis in that vicinity.
  79.    If you don't see a problem at that point, the next thing to do is to
  80. type `C-M-q' at the beginning of the defun.  A range of lines will
  81. probably shift left; if so, the missing open parenthesis or spurious
  82. close parenthesis is probably near the first of those lines.  (However,
  83. don't assume this is true; study the code to make sure.)  Once you have
  84. found the discrepancy, undo the `C-M-q', since the old indentation is
  85. probably appropriate to the intended parentheses.
  86. File: elisp,  Node: Compilation Errors,  Next: Edebug,  Prev: Syntax Errors,  Up: Debugging
  87. Debugging Problems in Compilation
  88. =================================
  89.    When an error happens during byte compilation, it is normally due to
  90. invalid syntax in the program you are compiling.  The compiler prints a
  91. suitable error message in the `*Compile-Log*' buffer, and then stops.
  92. The message may state a function name in which the error was found, or
  93. it may not.  Regardless, here is how to find out where in the file the
  94. error occurred.
  95.    What you should do is switch to the buffer ` *Compiler Input*'.
  96. (Note that the buffer name starts with a space, so it does not show up
  97. in `M-x list-buffers'.)  This buffer contains the program being
  98. compiled, and point shows how far the byte compiler was able to read.
  99.    If the error was due to invalid Lisp syntax, point shows exactly
  100. where the invalid syntax was *detected*.  The cause of the error is not
  101. necessarily near by!  Use the techniques in the previous section to find
  102. the error.
  103.    If the error was detected while compiling a form that had been read
  104. successfully, then point is located at the end of the form.  In this
  105. case, it can't localize the error precisely, but can still show you
  106. which function to check.
  107. File: elisp,  Node: Edebug,  Prev: Compilation Errors,  Up: Debugging
  108. Edebug
  109. ======
  110.    Edebug is a source-level debugger for Emacs Lisp programs that
  111. provides the following features:
  112.    * Step through evaluation, stopping before and after each expression.
  113.    * Set conditional or unconditional breakpoints.
  114.    * Trace slow or fast stopping briefly at each stop point, or each
  115.      breakpoint.
  116.    * Evaluate expressions as if outside of Edebug.
  117.    * Automatically reevaluate a list of expressions and display their
  118.      results each time Edebug updates the display.
  119.    * Output trace info on function enter and exit.
  120.    The first three sections of this chapter should tell you enough about
  121. Edebug to enable you to use it.
  122. * Menu:
  123. * Using Edebug::        Introduction to use of Edebug.
  124. * Prepare: Edebug Prepare.    You must prepare a function or macro definition
  125.                   in order to debug it with Edebug.
  126. * Edebug Modes::        Execution modes, stopping more or less often.
  127. * Stepping::            Commands to step to a specified place.
  128. * Breakpoints::            Setting breakpoints to make the program stop.
  129. * Views::            Viewing the outside buffer and window status.
  130. * Eval: Edebug Eval.        Evaluating expressions within Edebug.
  131. * Eval List::            Expressions whose values are displayed
  132.                   each time you enter Edebug.
  133. * Misc: Edebug Misc.        Miscellaneous
  134. * Printing::            Printing circular structure in Edebug.
  135. * The Outside Context::        Data that Edebug saves and restores.
  136. * Macro Calls::            Explaining how to handle macro calls.
  137. * Options: Edebug Options.    Option variables for customizing Edebug.
  138. File: elisp,  Node: Using Edebug,  Next: Edebug Prepare,  Up: Edebug
  139. Using Edebug
  140. ------------
  141.    To debug a Lisp program with Edebug, you must first "prepare" the
  142. Lisp functions that you want to debug.  *Note Edebug Prepare::.
  143.    Once a function is prepared, any call to the function activates
  144. Edebug.  This involves entering a recursive edit which is a level of
  145. Edebug activation.
  146.    Activating Edebug may stop execution and let you step through the
  147. function, or it may continue execution while checking for debugging
  148. commands, depending on the selected Edebug execution mode.  *Note
  149. Edebug Modes::.
  150.    Within Edebug, you normally view an Emacs buffer showing the source
  151. of the Lisp function you are debugging.  We call this the "Edebug
  152. buffer"--but note that it is not always the same buffer, and it is not
  153. reserved for Edebug use.
  154.    An arrow at the left margin indicates the line where the function is
  155. executing.  Point initially shows where within the line the function is
  156. executing, but this ceases to be true if you move point yourself.
  157.    If you prepare the definition of `fac' (shown below) for Edebug and
  158. then execute `(fac 3)', here is what you normally see.  Point is at the
  159. open-parenthesis before `if'.
  160.      (defun fac (n)
  161.      =>-!-(if (< 0 n)
  162.            (* n (fac (1- n)))
  163.          1))
  164.    The places within a function where Edebug can stop execution are
  165. called "stop points".  These occur both before and after each
  166. subexpression that is a list, and also after each variable reference.
  167. Stop points before variables are optional, under the control of the
  168. value of `edebug-stop-before-symbols'.  Here we show with periods the
  169. stop points normally found in the function `fac':
  170.      (defun fac (n)
  171.        .(if .(< 0 n.).
  172.            .(* n. .(fac (1- n.).).).
  173.          1).)
  174.    While a buffer is the Edebug buffer, the special commands of Edebug
  175. are available in it, instead of many usual editing commands.  Type `?'
  176. to display a list of Edebug commands.  In particular, you can exit the
  177. innermost Edebug activation level with `C-]', and you can return all
  178. the way to top level with `q'.
  179.    For example, you can type the Edebug command SPC to execute until
  180. the next stop point.  If you type SPC once after entry to `fac', here
  181. is the state that you get:
  182.      (defun fac (n)
  183.      =>(if -!-(< 0 n)
  184.            (* n (fac (1- n)))
  185.          1))
  186.    When Edebug stops execution after an expression, it displays the
  187. expression's value in the echo area.  Use the `r' command to display
  188. the value again later.
  189.    While Edebug is active, it catches all errors (if `debug-on-error' is
  190. non-`nil') and quits (if `debug-on-quit' is non-`nil') instead of the
  191. standard debugger.  When this happens, Edebug displays the last stop
  192. point that it knows about.  This may be the location of a call to a
  193. function which was not prepared for Edebug debugging, within which the
  194. error actually occurred.
  195. File: elisp,  Node: Edebug Prepare,  Next: Edebug Modes,  Prev: Using Edebug,  Up: Edebug
  196. Preparing Functions for Edebug
  197. ------------------------------
  198.    In order to use Edebug to debug a function, you must first "prepare"
  199. the function.  Preparing a function inserts additional code into it
  200. which invokes Edebug at the proper places.
  201.    Any call to an Edebug-prepared function activates Edebug.  This may
  202. or may not stop execution, depending on the Edebug execution mode in
  203. use.  Some Edebug modes only update the display to indicate the
  204. progress of the evaluation without stopping execution.  The default
  205. initial Edebug mode is `step' which does stop execution.  *Note Edebug
  206. Modes::.
  207.    Once you have loaded Edebug, the command `C-M-x' is redefined so
  208. that when used on a function or macro definition, it prepares the
  209. function or macro if given a prefix argument.  If the variable
  210. `edebug-all-defuns' is non-`nil', that inverts the meaning of the
  211. prefix argument: then `C-M-x' prepares the function or macro *unless*
  212. it has a prefix argument.  The default value of `edebug-all-defuns' is
  213. `nil'.  The command `M-x edebug-all-defuns' toggles the value of the
  214. variable `edebug-all-defuns'.
  215.    If `edebug-all-defuns' is non-`nil', then the commands `eval-region'
  216. and `eval-current-buffer' also prepare any functions and macros whose
  217. definitions they evaluate.
  218.    Loading a file does not prepare functions and macros for Edebug.
  219.    See *Note Evaluation:: for discussion of other evaluation functions
  220. available inside of Edebug.
  221. File: elisp,  Node: Edebug Modes,  Next: Stepping,  Prev: Edebug Prepare,  Up: Edebug
  222. Edebug Modes
  223. ------------
  224.    Edebug supports several execution modes for running the program you
  225. are debugging.  We call these alternatives "Edebug modes"; do not
  226. confuse them with major modes or minor modes.  The current Edebug mode
  227. determines how Edebug displays the progress of the evaluation, whether
  228. it stops at each stop point, or continues to the next breakpoint, for
  229. example.
  230.    Normally, you specify the Edebug mode for execution by typing a
  231. command to continue the program in a certain mode.  Here is a table of
  232. these commands.  All except for `S' resume execution of the program, at
  233. least for a certain distance.
  234.      Stop: don't execute any more of the program for now, just wait for
  235.      more Edebug commands.
  236. `SPC'
  237.      Step: stop at the next stop point encountered.
  238.      Trace: pause one second at each Edebug stop point.
  239.      Rapid trace: mention each stop point, but don't actually pause.
  240.      Go: run until the next breakpoint.  *Note Breakpoints::.
  241.      Continue: pause for one second at each breakpoint, but don't stop.
  242.      Continue: mention each breakpoint, but don't actually pause.
  243.      Non-stop: ignore breakpoints.  You can still stop the program by
  244.      typing `S'.
  245.    In general, the execution modes earlier in the above list run the
  246. program more slowly or stop sooner.
  247.    When you enter a new Edebug level, the mode comes from the value of
  248. the variable `edebug-initial-mode'.  By default, this specifies "step"
  249. mode.  If the mode thus specified is not stop mode, then the Edebug
  250. level executes the program (or part of it).
  251.    While executing or tracing, you can interrupt the execution by typing
  252. any Edebug command.  Edebug stops the program at the next stop point and
  253. then executes the command that you typed.  For example, typing `t'
  254. during execution switches to trace mode at the next stop point.
  255.    You can use the `S' command to stop execution without doing anything
  256. else.
  257.    If your function happens to read input, a character you hit
  258. intending to interrupt execution may be read by the function instead.
  259. You can avoid such unintended results by paying attention to when your
  260. program wants input.
  261.    Keyboard macros containing the commands in this section do not
  262. completely work: exiting from Edebug, to resume the program, loses
  263. track of the keyboard macro.  This is not easy to fix.
  264. File: elisp,  Node: Stepping,  Next: Breakpoints,  Prev: Edebug Modes,  Up: Edebug
  265. Stepping
  266. --------
  267.      Run the program forward over one expression.  More precisely, set a
  268.      temporary breakpoint at the position that `C-M-f' would reach,
  269.      then execute in go mode so that the program will stop at
  270.      breakpoints.  See *Note Breakpoints:: for the details on
  271.      breakpoints.
  272.      With a prefix argument N, the temporary breakpoint is placed N
  273.      sexps beyond point.  If the containing list ends before N more
  274.      elements, then the place to stop is after the containing
  275.      expression.
  276.      Be careful that the position `C-M-f' finds is a place that the
  277.      program will really get to; this may not be true in a
  278.      `condition-case', for example.
  279.      This command does `forward-sexp' starting at point rather than the
  280.      stop point, thus providing more flexibility.  If you want to
  281.      execute one expression from the current stop point, type `w'
  282.      first, to move point there.
  283.      Run the program until the end of the containing sexp.  If the
  284.      containing sexp is the top level defun, run until just before the
  285.      function returns.  If that is where you are now, return from the
  286.      function and then stop.
  287.      This command does not exit the currently executing function unless
  288.      you are positioned after the last sexp of the function.
  289.      If the program does a non-local exit, it may fail to reach the
  290.      temporary breakpoint that this command sets.
  291.      Step into the function about to be called.  Use this command
  292.      before any of the arguments of the function call are evaluated,
  293.      since otherwise it is too late.
  294.      One undesirable side effect of using `edebug-step-in' is that the
  295.      next time the stepped-into function is called, Edebug will be
  296.      called there as well.
  297.      Proceed to the stop point near where point is.  This uses a
  298.      temporary breakpoint.
  299.    The `f' command runs the program forward over one expression.  More
  300. precisely, set a temporary breakpoint at the position that `C-M-f'
  301. would reach, then execute in go mode so that the program will stop at
  302. breakpoints.  See *Note Breakpoints:: for the details on breakpoints.
  303.    With a prefix argument N, the temporary breakpoint is placed N sexps
  304. beyond point.  If the containing list ends before N more elements, then
  305. the place to stop is after the containing expression.
  306.    Be careful that the position `C-M-f' finds is a place that the
  307. program will really get to; this may not be true in a `condition-case',
  308. for example.
  309.    The `f' command uses the existing value of point as the basis for
  310. setting the breakpoint, because that is more flexible.  To execute one
  311. expression *from the current stop point*, type `w' and then `f'.
  312.    The `o' command continues "out of" an expression.  It places a
  313. temporary breakpoints at the end of the containing sexp.  If the
  314. containing sexp is the top level defun, it continues until just before
  315. the function returns.  If that is where you are now, it returns from the
  316. function and then stops.
  317.    This command does not exit the currently executing function unless
  318. you are positioned after the last sexp of the function.
  319.    The `i' command steps into the function about to be called.  Use
  320. this command before any of the arguments of the function call are
  321. evaluated, since otherwise it is too late.
  322.    One undesirable side effect of using `i' is that the next time the
  323. stepped-into function is called, Edebug will be called there as well.
  324.    The `h' command proceeds to the stop point near where point is,
  325. using a temporary breakpoint.
  326.    All the commands in this section may fail to work as expected in case
  327. of nonlocal exit, because a nonlocal exit can bypass the temporary
  328. breakpoint where you expected the program to stop.
  329. File: elisp,  Node: Edebug Misc,  Next: Printing,  Prev: Eval List,  Up: Edebug
  330. Miscellaneous
  331. -------------
  332.    Some miscellaneous commands are described here.
  333. `C-]'
  334.      Abort one level of Edebug activity.
  335.      Return to the top level editor command loop.  This exits all
  336.      recursive editing levels, including all levels of Edebug activity.
  337.      Redisplay the result of the previous expression in the echo area.
  338.      Display a backtrace, excluding Edebug's own functions for clarity.
  339.      You cannot use debugger commands in the backtrace buffer in Edebug
  340.      as you would in the standard debugger.
  341.      The backtrace buffer is killed automatically when you continue
  342.      execution.
  343. File: elisp,  Node: Breakpoints,  Next: Views,  Prev: Stepping,  Up: Edebug
  344. Breakpoints
  345. -----------
  346.    While using Edebug, you can specify "breakpoints" in the program you
  347. are testing: points where execution should stop.  You can set a
  348. breakpoint at any stop point, as defined in *Note Using Edebug::--even
  349. before a symbol.  For setting and unsetting breakpoints, the stop point
  350. that is affected is the first one at or after point in the Edebug
  351. buffer.  Here are the Edebug commands for breakpoints:
  352.      Set a breakpoint at the stop point at or after point.  If you use a
  353.      prefix argument, the breakpoint is temporary (it turns off the
  354.      first time it stops the program).
  355.      Unset the breakpoint (if any) at the stop point at or after the
  356.      current point.
  357. `x COND RET'
  358.      Set a conditional breakpoint which stops the program only if COND
  359.      evaluates to a non-`nil' value.  If you use a prefix argument, the
  360.      breakpoint is temporary (it turns off the first time it stops the
  361.      program).
  362.      Move point to the next breakpoint in the current function
  363.      definition.
  364.    While in Edebug, you can set a breakpoint with `b'
  365. (`edebug-set-breakpoint') and unset one with `u'
  366. (`edebug-unset-breakpoint').  First you must move point to a position
  367. at or before the desired Edebug stop point, then hit the key to change
  368. the breakpoint.  Unsetting a breakpoint that has not been set does
  369. nothing.
  370.    Reevaluating the function with `edebug-defun' clears all breakpoints
  371. in the function.
  372.    A "conditional breakpoint" tests a condition each time the program
  373. gets there, to decide whether to stop.  To set a conditional breakpoint,
  374. use `x', and specify the condition expression in the minibuffer.
  375.    You can make both conditional and unconditional breakpoints
  376. "temporary" by using a prefix arg to the command to set the breakpoint.
  377. After breaking at a temporary breakpoint, it is automatically cleared.
  378.    Edebug always stops or pauses at a breakpoint except when the Edebug
  379. mode is Go-nonstop.  In that mode, it ignores breakpoints entirely.
  380.    To find out where your breakpoints are, use the `B'
  381. (`edebug-next-breakpoint') command, which moves point to the next
  382. breakpoint in the function following point, or to the first breakpoint
  383. if there are no following breakpoints.  This command does not continue
  384. execution--it just moves point in the buffer.
  385. File: elisp,  Node: Views,  Next: Edebug Eval,  Prev: Breakpoints,  Up: Edebug
  386. Views
  387. -----
  388.    These Edebug commands let you view aspects of the buffer and window
  389. status that obtained before entry to Edebug.
  390.      View the outside window configuration.
  391.      Temporarily display the outside current buffer with point at its
  392.      outside position.
  393.      Switch back to the buffer showing the currently executing
  394.      function, and move point back to the current stop point.
  395.      Forget the saved outside window configuration--so that the current
  396.      window configuration will remain unchanged when you next exit
  397.      Edebug (by continuing the program).  Also toggle the
  398.      `edebug-save-windows' variable.
  399. File: elisp,  Node: Edebug Eval,  Next: Eval List,  Prev: Views,  Up: Edebug
  400. Evaluation
  401. ----------
  402.    While within Edebug, you can evaluate expressions "as if" Edebug were
  403. not running.  Edebug tries to be invisible to the expression's
  404. evaluation.
  405. `e EXP RET'
  406.      Evaluate expression EXP in the context outside of Edebug.  That
  407.      is, Edebug tries to avoid altering the effect of EXP.
  408. `M-ESC EXP RET'
  409.      Evaluate expression EXP in the context of Edebug itself.
  410. `C-x C-e'
  411.      Evaluate the expression in the buffer before point, in the context
  412.      outside of Edebug.
  413. File: elisp,  Node: Eval List,  Next: Edebug Misc,  Prev: Edebug Eval,  Up: Edebug
  414. Evaluation List Buffer
  415. ----------------------
  416.    You can use the "evaluation list buffer", called `*edebug*', to
  417. evaluate expressions interactively.  You can also set up the
  418. "evaluation list" of expressions to be evaluated automatically each
  419. time Edebug is reentered.
  420.      Switch to the evaluation list buffer `*edebug*'.
  421.    In the `*edebug*' buffer you can use the commands of Lisp
  422. Interaction as well as these special commands:
  423. `LFD'
  424.      Evaluate the expression before point, in the context outside of
  425.      Edebug, and insert the value in the buffer.
  426. `C-x C-e'
  427.      Evaluate the expression before point, in the context outside of
  428.      Edebug.
  429. `C-c C-u'
  430.      Build a new evaluation list from the first expression of each
  431.      group, reevaluate and redisplay.  Groups are separated by a line
  432.      starting with a comment.
  433. `C-c C-d'
  434.      Delete the evaluation list group that point is in.
  435. `C-c C-w'
  436.      Switch back to the Edebug buffer at the current stop point.
  437.    You can evaluate expressions in the evaluation list window with
  438. `LFD' or `C-x C-e', just as you would in `*scratch*'; but they are
  439. evaluated in the context outside of Edebug.
  440.    The expressions you enter interactively (and their results) are lost
  441. when you continue execution of your function unless you add them to the
  442. evaluation list with `C-c C-u' (`edebug-update-eval-list').  This
  443. command builds a new list from the first expression of each "evaluation
  444. list group".  Groups are separated by a line starting with a comment.
  445.    When the evaluation list is redisplayed, each expression is displayed
  446. followed by the result of evaluating it, and a comment line.  If an
  447. error occurs during an evaluation, the error message is displayed in a
  448. string as if it were the result.  Therefore expressions that use
  449. variables not currently valid do not interrupt your debugging.
  450.    Here is an example of what the evaluation list window looks like
  451. after several expressions have been added to it:
  452.      (current-buffer)
  453.      #<buffer *scratch*>
  454.      ;---------------------------------------------------------------
  455.      (point-min)
  456.      1
  457.      ;---------------------------------------------------------------
  458.      (point-max)
  459.      2
  460.      ;---------------------------------------------------------------
  461.      edebug-outside-point-max
  462.      "Symbol's value as variable is void: edebug-outside-point-max"
  463.      ;---------------------------------------------------------------
  464.      (recursion-depth)
  465.      0
  466.      ;---------------------------------------------------------------
  467.      this-command
  468.      eval-last-sexp
  469.      ;---------------------------------------------------------------
  470.    To delete a group, move point into it and type `C-c C-d'
  471. (`edebug-delete-eval-item'), or simply delete the text for it and
  472. update the evaluation list with `C-c C-u'.  When you add a new group,
  473. be sure to add a comment at the beginning.
  474.    After selecting `*edebug*', you can return to the source code buffer
  475. (the Edebug buffer) with `C-c C-w'.  The `*edebug*' buffer is killed
  476. when you continue execution of your function, and recreated next time
  477. it is needed.
  478. File: elisp,  Node: Printing,  Next: The Outside Context,  Prev: Edebug Misc,  Up: Edebug
  479. Printing
  480. --------
  481.    If the results of your expressions contain circular references to
  482. other parts of the same structure, you can print them more usefully
  483. with the `custom-print'.
  484.    To load the package and activate custom printing only for Edebug,
  485. simply use the command `edebug-install-custom-print-funcs'.  Then set
  486. the variable `print-circle' to enable special handling of circular
  487. structure.  To restore the standard print functions, use
  488. `edebug-reset-print-funcs'.
  489. File: elisp,  Node: The Outside Context,  Next: Macro Calls,  Prev: Printing,  Up: Edebug
  490. The Outside Context
  491. -------------------
  492.    Edebug tries to be transparent to the program you are debugging, but
  493. it does not succeed completely.  In addition, most evaluations you do
  494. within Edebug (see *Note Evaluation::) occur in the same outside context
  495. which is temporarily restored for the evaluation.  This section explains
  496. precisely how use Edebug fails to be completely transparent.
  497. * Menu:
  498. * Just Checking::        Just Checking
  499. * Outside Window Configuration::  Outside Window Configuration
  500. * Recursive Edit::        Recursive Edit
  501. * Side Effects::        Side Effects
  502. File: elisp,  Node: Just Checking,  Next: Outside Window Configuration,  Up: The Outside Context
  503. Just Checking
  504. .............
  505.    Whenever Edebug is entered just to think about whether to take some
  506. action, it needs to save and restore certain data.
  507.    * `max-lisp-eval-depth' and `max-specpdl-size' are both incremented
  508.      for each `edebug-enter' call so that your code should not be
  509.      impacted by Edebug frames on the stack.
  510.    * The state of keyboard macro execution is saved and cleared out.
  511. File: elisp,  Node: Outside Window Configuration,  Next: Recursive Edit,  Prev: Just Checking,  Up: The Outside Context
  512. Outside Window Configuration
  513. ............................
  514.    When Edebug needs to display something (e.g., in trace mode), it
  515. saves the current window configuration from "outside" Edebug (*note
  516. Window Configurations::.).  When you exit Edebug (by continuing the
  517. program), it restores the previous window configuration.
  518.    Emacs redisplays only when it pauses.  Usually, when you continue
  519. Edebug, the program comes back into Edebug at a breakpoint or after
  520. stepping, without pausing or reading input in between.  In such cases,
  521. Emacs never gets a chance to redisplay the "outside" configuration.
  522. What you see is the window configuration for within Edebug, with no
  523. interruption.
  524.    The window configuration proper does not include which buffer is
  525. current or where point and mark are in the current buffer, but Edebug
  526. saves and restores these also.
  527.    Entry to Edebug for displaying something also saves and restores the
  528. following data.  (Some of these variables are deliberately not restored
  529. if an error or quit signal occurs.)
  530.    * The position of point in the Edebug buffer is saved and restored
  531.      if the outside current buffer is the same as the Edebug buffer.
  532.    * The outside window configuration, as described above, is saved and
  533.      restored if `edebug-save-windows' is non-`nil'.
  534.    * The current buffer, and point and mark in the current buffer are
  535.      normally saved and restored even if the current buffer is the same
  536.      as the Edebug buffer.
  537.    * The value of point in each displayed buffers is saved and restored
  538.      if `edebug-save-displayed-buffer-points' is non-`nil'.
  539.    * The variables `overlay-arrow-position' and `overlay-arrow-string'
  540.      are saved and restored.  This permits recursive use of Edebug, and
  541.      use of Edebug while using GUD.
  542.    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
  543.      shows up in the window.
  544. File: elisp,  Node: Recursive Edit,  Next: Side Effects,  Prev: Outside Window Configuration,  Up: The Outside Context
  545. Recursive Edit
  546. ..............
  547.    When Edebug is entered and actually reads commands from the user, it
  548. saves (and later restores) these additional data:
  549.    * The current match data, for whichever buffer was current.
  550.    * `last-command', `this-command', `last-command-char', and
  551.      `last-input-char'.  Commands used within Edebug do not affect these
  552.      variables outside of Edebug.
  553.      But note that it is not possible to preserve the status reported by
  554.      `(this-command-keys)' and the variable `unread-command-char'.
  555.    * `standard-output' and `standard-input'.
  556. File: elisp,  Node: Side Effects,  Prev: Recursive Edit,  Up: The Outside Context
  557. Side Effects
  558. ............
  559.    Edebug operation unavoidably alters some data in Emacs, and this can
  560. interfere with debugging certain programs.
  561.    * Lisp stack usage is increased, but the limits,
  562.      `max-lisp-eval-depth' and `max-specpdl-size', are also increased
  563.      proportionally.
  564.    * The key sequence returned by `this-command-keys' is changed by
  565.      executing commands within Edebug and there appears to be no way to
  566.      reset the key sequence from Lisp.
  567.    * Edebug cannot save and restore the value of `unread-command-char'
  568.      or `unread-command-events'.  Entering Edebug while these variables
  569.      have nontrivial values can interfere with execution of the program
  570.      you are debugging.
  571.    * Complex commands executed while in Edebug are added to the variable
  572.      `command-history'.  In rare cases this can alter execution.
  573.    * Within Edebug, the recursion depth appears one deeper than the
  574.      recursion depth outside Edebug.
  575.    * Horizontal scrolling of the Edebug buffer is not recovered.
  576. File: elisp,  Node: Macro Calls,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
  577. Macro Calls
  578. -----------
  579.    When Edebug prepares for stepping through an expression that uses a
  580. Lisp macro, it needs additional advice to do the job properly.  This is
  581. because there is no way to tell which parts of the macro call are forms
  582. to be evaluated.  You must explain the format of calls to each macro to
  583. enable Edebug to handle it.  To do this, use `def-edebug-form-spec' to
  584. define the format of calls to a given macro.
  585.  - Macro: def-edebug-form-spec MACRO ARGPATTERN
  586.      Specify which parts of a call to macro MACRO are subexpressions to
  587.      be evaluated.  The second argument, ARGPATTERN, details what the
  588.      argument list looks like.
  589.    Here is a table of the possibilities for ARGPATTERN and its
  590. subexpressions:
  591.      A list of any number of evaluated arguments.
  592.      A list of unevaluated arguments.
  593. `sexp'
  594.      A single unevaluated object.
  595. `form'
  596.      A single evaluated expression.
  597. `symbolp'
  598.      An unevaluated symbol.
  599. `integerp'
  600.      An unevaluated number.
  601. `stringp'
  602.      An unevaluated string.
  603. `vectorp'
  604.      An unevaluated vector.
  605. `atom'
  606.      An unevaluated object that is not a cons cell.
  607. `function'
  608.      A function argument: a quoted symbol, a quoted lambda expression,
  609.      or a form (that should evaluate to a function or lambda
  610.      expression).  Edebug treats the body of a lambda expression
  611.      treated as evaluated.
  612. `FUNCTION'
  613.      A function serves as a predicate--it designates the set of possible
  614.      arguments for which it would return non-`nil'.
  615. `'OBJECT'
  616.      The precise object OBJECT, treated as unevaluated.
  617. `(PATTERNS)'
  618.      A list whose elements are described by PATTERNS.  A sublist of the
  619.      same format as the top level, processed recursively.
  620. `[PATTERNS]'
  621.      A sequence of arguments that are described by PATTERNS.
  622. `&optional'
  623.      This symbol serves as a flag saying that all following elements in
  624.      the specification list at this level are optional.  They may or
  625.      may not match arguments; as soon as one does not match, processing
  626.      of the specification list at this level terminates.  To make just
  627.      one item optional, use `[&optional PATTERN]'.
  628. `&rest'
  629.      This symbol serves as a flag saying that the following elements in
  630.      the specification list at this level may be repeated, in order,
  631.      zero or more times.  Only one `&rest' may appear at the same level
  632.      of a specification list, and `&rest' must not be followed by
  633.      `&optional'.
  634.      To specify repetition of certain types of arguments, followed by
  635.      dissimilar arguments, use `[&rest PATTERNS...]'.
  636. `&or'
  637.      This symbol serves as an operator saying that the following
  638.      elements in the specification list at this level are alternatives.
  639.      To group two or more list elements as one alternative, bracket
  640.      them in `[...]'.  Only one `&or' may appear in a list, and it may
  641.      not be followed by `&optional' or `&rest'.  One of the
  642.      alternatives must match, unless the `&or' is preceded by
  643.      `&optional' or `&rest'.
  644.    If the actual arguments of a macro call fail to match the
  645. specification, taking account of alternatives, optional arguments and
  646. repeated arguments, Edebug reports a syntax error in use of the macro.
  647.    The combination of backtracking, `&optional', `&rest', `&or', and
  648. `[...]' for grouping provides the equivalent of regular expressions.
  649. The `(...)' lists require balanced parentheses, which is the only
  650. context free (finite state with stack) construct supported.
  651.    Here are some examples of using `def-edebug-form-spec'.  First, for
  652. the `let' special form:
  653.      (def-edebug-form-spec let
  654.        '((&rest
  655.          &or symbolp (symbolp &optional form))
  656.         &rest form))
  657.    Here's the spec for the `for' loop macro (*note Problems with
  658. Macros::.) and for the `case' and `do' macros in `cl.el':
  659.      (def-edebug-form-spec for
  660.        '(symbolp 'from form 'to form 'do &rest form))
  661.      
  662.      (def-edebug-form-spec case
  663.        '(form &rest (sexp form)))
  664.      
  665.      (def-edebug-form-spec do
  666.        '((&rest &or symbolp (symbolp &optional form form))
  667.          (form &rest form)
  668.          &rest body))
  669.    Finally, the functions `mapcar', `mapconcat', `mapatoms', `apply',
  670. and `funcall' all take function arguments, and Edebug defines
  671. specifications for them.  Here's one example:
  672.      (def-edebug-form-spec apply '(function &rest form))
  673.    The backquote (``') macro results in an expression that is not
  674. necessarily evaluated.  Edebug cannot step through code generated by use
  675. of backquote.
  676. File: elisp,  Node: Edebug Options,  Prev: Macro Calls,  Up: Edebug
  677. Edebug Options
  678. --------------
  679.    These options affect the behavior of Edebug:
  680.  - User Option: edebug-all-defuns
  681.      If non-`nil', normal evaluation of `defun' and `defmacro' forms
  682.      prepares the functions and macros for stepping with Edebug.  This
  683.      applies to `eval-defun', `eval-region' and `eval-current-buffer'.
  684.      The default value is `nil'.
  685.  - User Option: edebug-stop-before-symbols
  686.      If non-`nil', Edebug places stop points before symbols as well as
  687.      after.
  688.      This option takes effect for a function when you prepare it for
  689.      stepping with Edebug.  Changing the option's value during
  690.      execution of Edebug has no effect on the functions already set up
  691.      for Edebug execution.
  692.  - User Option: edebug-save-windows
  693.      If non-`nil', save and restore window configuration on Edebug
  694.      calls.  It takes some time to save and restore, so if your program
  695.      does not care what happens to the window configurations, it is
  696.      better to set this variable to `nil'.
  697.      The default value is `t'.
  698.  - User Option: edebug-save-point
  699.      If non-`nil', Edebug saves and restores point and the mark in
  700.      source code buffers.  The default value is `t'.
  701.  - User Option: edebug-save-displayed-buffer-points
  702.      If non-`nil', save and restore point in all buffers when entering
  703.      Edebug mode.
  704.      Saving and restoring point in other buffers is necessary if you are
  705.      debugging code that changes the point of a buffer which is
  706.      displayed in a non-selected window.  If Edebug or the user then
  707.      selects the window, the buffer's point will be changed to the
  708.      window's point.
  709.      Saving and restoring is an expensive operation since it visits each
  710.      window and each displayed buffer twice for each Edebug call, so it
  711.      is best to avoid it if you can.
  712.      The default value is `nil'.
  713.  - User Option: edebug-initial-mode
  714.      If this variable is non-`nil', it specifies an Edebug mode to start
  715.      in each time the program enters a new Edebug recursive-edit level.
  716.      Possible values are `step', `go', `Go-nonstop', `trace',
  717.      `Trace-fast', `continue', and `Continue-fast'.
  718.      The default value is `step'.
  719.  - User Option: edebug-trace
  720.      Non-`nil' means display a trace of function entry and exit.
  721.      Tracing output is displayed in a buffer named `*edebug-trace*', one
  722.      function entry or exit per line, indented by the recursion level.
  723.      You can customize this display by replacing the functions
  724.      `edebug-print-trace-entry' and `edebug-print-trace-exit'.
  725.      The default value is `nil'.
  726. File: elisp,  Node: Streams,  Next: Minibuffers,  Prev: Debugging,  Up: Top
  727. Reading and Printing Lisp Objects
  728. *********************************
  729.    "Printing" and "reading" are the operations of converting Lisp
  730. objects to textual form and vice versa.  They use the printed
  731. representations and read syntax described in *Note Types of Lisp
  732. Object::.
  733.    This chapter describes the Lisp functions for reading and printing.
  734. It also describes "streams", which specify where to get the text (if
  735. reading) or where to put it (if printing).
  736. * Menu:
  737. * Streams Intro::     Overview of streams, reading and printing.
  738. * Input Streams::     Various data types that can be used as input streams.
  739. * Input Functions::   Functions to read Lisp objects from text.
  740. * Output Streams::    Various data types that can be used as output streams.
  741. * Output Functions::  Functions to print Lisp objects as text.
  742. * Output Variables::  Variables that control what the printing functions do.
  743. File: elisp,  Node: Streams Intro,  Next: Input Streams,  Up: Streams
  744. Introduction to Reading and Printing
  745. ====================================
  746.    "Reading" a Lisp object means parsing a Lisp expression in textual
  747. form and producing a corresponding Lisp object.  This is how Lisp
  748. programs get into Lisp from files of Lisp code.  We call the text the
  749. "read syntax" of the object.  For example, reading the text `(a . 5)'
  750. returns a cons cell whose CAR is `a' and whose CDR is the number 5.
  751.    "Printing" a Lisp object means producing text that represents that
  752. object--converting the object to its printed representation.  Printing
  753. the cons cell described above produces the text `(a . 5)'.
  754.    Reading and printing are more or less inverse operations: printing
  755. the object that results from reading a given piece of text often
  756. produces the same text, and reading the text that results from printing
  757. an object usually produces a similar-looking object.  For example,
  758. printing the symbol `foo' produces the text `foo', and reading that text
  759. returns the symbol `foo'.  Printing a list whose elements are `a' and
  760. `b' produces the text `(a b)', and reading that text produces a list
  761. (but not the same list) with elements are `a' and `b'.
  762.    However, these two operations are not precisely inverses.  There are
  763. two kinds of exceptions:
  764.    * Printing can produce text that cannot be read.  For example,
  765.      buffers, windows, subprocesses and markers print into text that
  766.      starts with `#'; if you try to read this text, you get an error.
  767.      There is no way to read those data types.
  768.    * One object can have multiple textual representations.  For example,
  769.      `1' and `01' represent the same integer, and `(a b)' and `(a .
  770.      (b))' represent the same list.  Reading will accept any of the
  771.      alternatives, but printing must choose one of them.
  772. File: elisp,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Streams
  773. Input Streams
  774. =============
  775.    Most of the Lisp functions for reading text take an "input stream"
  776. as an argument.  The input stream specifies where or how to get the
  777. characters of the text to be read.  Here are the possible types of input
  778. stream:
  779. BUFFER
  780.      The input characters are read from BUFFER, starting with the
  781.      character directly after point.  Point advances as characters are
  782.      read.
  783. MARKER
  784.      The input characters are read from the buffer that MARKER is in,
  785.      starting with the character directly after the marker.  The marker
  786.      position advances as characters are read.  The value of point in
  787.      the buffer has no effect when the stream is a marker.
  788. STRING
  789.      The input characters are taken from STRING, starting at the first
  790.      character in the string and using as many characters as required.
  791. FUNCTION
  792.      The input characters are generated by FUNCTION, one character per
  793.      call.  Normally FUNCTION is called with no arguments, and should
  794.      return a character.
  795.      Occasionally FUNCTION is called with one argument (always a
  796.      character).  When that happens, FUNCTION should save the argument
  797.      and arrange to return it on the next call.  This is called
  798.      "unreading" the character; it happens when the Lisp reader reads
  799.      one character too many and want to "put it back where it came
  800.      from".
  801.      `t' used as a stream means that the input is read from the
  802.      minibuffer.  In fact, the minibuffer is invoked once and the text
  803.      given by the user is made into a string that is then used as the
  804.      input stream.
  805. `nil'
  806.      `nil' used as a stream means that the value of `standard-input'
  807.      should be used instead; that value is the "default input stream",
  808.      and must be a non-`nil' input stream.
  809. SYMBOL
  810.      A symbol as output stream is equivalent to the symbol's function
  811.      definition (if any).
  812.    Here is an example of reading from a stream which is a buffer,
  813. showing where point is located before and after:
  814.      ---------- Buffer: foo ----------
  815.      This-!- is the contents of foo.
  816.      ---------- Buffer: foo ----------
  817.      
  818.      (read (get-buffer "foo"))
  819.           => is
  820.      (read (get-buffer "foo"))
  821.           => the
  822.      
  823.      ---------- Buffer: foo ----------
  824.      This is the-!- contents of foo.
  825.      ---------- Buffer: foo ----------
  826. Note that the first read skips a space at the beginning of the buffer.
  827. Reading skips any amount of whitespace preceding the significant text.
  828.    In Emacs 18, reading a symbol discarded the delimiter terminating the
  829. symbol.  Thus, point would end up at the beginning of `contents' rather
  830. than after `the'.  The Emacs 19 behavior is superior because it
  831. correctly handles input such as `bar(foo)' where the delimiter that
  832. ends one object is needed as the beginning of another object.
  833.    Here is an example of reading from a stream that is a marker,
  834. initialized to point at the beginning of the buffer shown.  The value
  835. read is the symbol `This'.
  836.      ---------- Buffer: foo ----------
  837.      This is the contents of foo.
  838.      ---------- Buffer: foo ----------
  839.      
  840.      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  841.           => #<marker at 1 in foo>
  842.      (read m)
  843.           => This
  844.      m
  845.           => #<marker at 6 in foo>   ;; After the first space.
  846.    Here we read from the contents of a string:
  847.      (read "(When in) the course")
  848.           => (When in)
  849.    The following example reads from the minibuffer.  The prompt is:
  850. `Lisp expression: '.  (That is always the prompt used when you read
  851. from the stream `t'.)  The user's input is shown following the prompt.
  852.      (read t)
  853.           => 23
  854.      ---------- Buffer: Minibuffer ----------
  855.      Lisp expression: `23 RET'
  856.      ---------- Buffer: Minibuffer ----------
  857.    Finally, here is an example of a stream that is a function, named
  858. `useless-stream'.  Before we use the stream, we initialize the variable
  859. `useless-list' to a list of characters.  Then each call to the function
  860. `useless-stream' obtains the next characters in the list or unreads a
  861. character by adding it to the front of the list.
  862.      (setq useless-list (append "XY()" nil))
  863.           => (88 89 40 41)
  864.      
  865.      (defun useless-stream (&optional unread)
  866.        (if unread
  867.            (setq useless-list (cons unread useless-list))
  868.          (prog1 (car useless-list)
  869.                 (setq useless-list (cdr useless-list)))))
  870.           => useless-stream
  871. Now we read using the stream thus constructed:
  872.      (read 'useless-stream)
  873.           => XY
  874.      
  875.      useless-list
  876.           => (41)
  877. Note that the close parenthesis remains in the list.  The reader has
  878. read it, discovered that it ended the input, and unread it.  Another
  879. attempt to read from the stream at this point would get an error due to
  880. the unmatched close parenthesis.
  881.  - Function: get-file-char
  882.      This function is used internally as an input stream to read from
  883.      the input file opened by the function `load'.  Don't use this
  884.      function yourself.
  885. File: elisp,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Streams
  886. Input Functions
  887. ===============
  888.    This section describes the Lisp functions and variables that pertain
  889. to reading.
  890.    In the functions below, STREAM stands for an input stream (see the
  891. previous section).  If STREAM is `nil' or omitted, it defaults to the
  892. value of `standard-input'.
  893.    An `end-of-file' error results if an unterminated list or vector is
  894. found.
  895.  - Function: read &optional STREAM
  896.      This function reads one textual Lisp expression from STREAM,
  897.      returning it as a Lisp object.  This is the basic Lisp input
  898.      function.
  899.  - Function: read-from-string STRING &optional START END
  900.      This function reads the first textual Lisp expression from the
  901.      text in STRING.  It returns a cons cell whose CAR is that
  902.      expression, and whose CDR is an integer giving the position of the
  903.      next remaining character in the string (i.e., the first one not
  904.      read).
  905.      If START is supplied, then reading begins at index START in the
  906.      string (where the first character is at index 0).  If END is also
  907.      supplied, then reading stops at that index as if the rest of the
  908.      string were not there.
  909.      For example:
  910.           (read-from-string "(setq x 55) (setq y 5)")
  911.                => ((setq x 55) . 11)
  912.           (read-from-string "\"A short string\"")
  913.                => ("A short string" . 16)
  914.           
  915.           ;; Read starting at the first character.
  916.           (read-from-string "(list 112)" 0)
  917.                => ((list 112) . 10)
  918.           ;; Read starting at the second character.
  919.           (read-from-string "(list 112)" 1)
  920.                => (list . 6)
  921.           ;; Read starting at the seventh character,
  922.           ;;   and stopping at the ninth.
  923.           (read-from-string "(list 112)" 6 8)
  924.                => (11 . 8)
  925.  - Variable: standard-input
  926.      This variable holds the default input stream: the stream that
  927.      `read' uses when the STREAM argument is `nil'.
  928.